﻿using Foxit.PDF;
using System;

namespace Sustainalytics.Reporting.Framework
{
    public static class Fonts
    {
        public static Font CalibriBoldItalic { get; set; }
        public static Font CalibriItalic { get; set; }
        public static Font CalibriBold { get; set; }
        public static Font CalibriRegular { get; set; }
        public static Font CalibriLight { get; set; }

        public static FontFamily CalibriFontFamily { get; set; }
        public static FontFamily CalibriLightFontFamily { get; set; }


        public static Font MontserratBold { get; set; }
        public static Font MontserratRegular { get; set; }
        public static Font RobotoBlack { get; set; }
        public static Font RobotoBold { get; set; }
        public static Font RobotoMedium { get; set; }
        public static Font RobotoRegular { get; set; }
        public static FontFamily RobotoFontFamily { get; set; }
        
        static Fonts()
        {
            CalibriBoldItalic = GetSystemFont("Calibri Bold Italic");
            CalibriItalic = GetSystemFont("Calibri Italic");
            CalibriBold = GetSystemFont("Calibri Bold");
            CalibriRegular = GetSystemFont("Calibri");
            CalibriLight = GetSystemFont("Calibri Light");
            CalibriFontFamily = new FontFamily("Calibri", CalibriRegular, CalibriBold, CalibriItalic, CalibriBoldItalic);
            CalibriLightFontFamily = new FontFamily("CalibriLight", CalibriLight, CalibriBold, CalibriItalic, CalibriBoldItalic);

            MontserratBold = GetSystemFont("Montserrat Bold");
            MontserratRegular = GetSystemFont("Montserrat Regular");
            
            RobotoRegular = GetSystemFont("Roboto Regular");
            RobotoBlack = GetSystemFont("Roboto Black");
            RobotoBold = GetSystemFont("Roboto Bold");
            RobotoMedium = GetSystemFont("Roboto Medium");

            RobotoFontFamily = new FontFamily("Roboto", RobotoRegular, RobotoBold, RobotoRegular, RobotoBold);
        }

        public static Font GetSystemFont(string fontName)
        {
            var font = Font.TimesRoman;

            try
            {
                if (Font.CanLoadSystemFont(fontName))
                {
                    font = Font.LoadSystemFont(fontName);
                }
                else
                {
                    throw new Exception(string.Format("System Font {0} not found", fontName));
                }
            }
            catch {
                //supress exception
            }

            return font;
        }
    }
}
